<?php

namespace Admin\Controller;

use Utuo\BackgroundController;

class LogController extends BackgroundController {
    // 模块
    private $module;
    
    // 模块与数据表对应关系
    private $tables = array(
        'Admin'=>'LogBackground',
        'Partner' => 'LogBackground',
        'My' => 'LogBackground',
        'Agent' => 'LogBackground',
        'Home' => 'LogForeground',
        'DisShop'=>'LogDisShop'
    );
    
	// 初始化
	public function _initialize() {
		$this->setControllerTitle('日志管理');
		$this->setActionTitle(array(
				'index' => '日志列表',
		));
		$this->module = I("module");
	}
	
	// 日志列表
	public function indexAction() {
		$condition = array(
		    'module' => $this->module
		);
		$model = M($this->tables[$this->module]." l");
		$model->where($condition);
		
		$clone = clone $model;
		$count = $clone->count();
		
		$page = $this->getPage();
		$pagesize = $this->getPageSize();
		$model->join("LEFT JOIN __CUSTOMER__ c ON l.cid=c.id");
		$model->join("LEFT JOIN __PARTNER__ p ON l.pid=p.id");
		$model->join("LEFT JOIN __AGENT__ a ON l.aid=a.id");
		$model->field("l.*,c.name AS customerName,p.name AS partnerName,a.name AS agentName");
		$lists = $model->limit($pagesize)->page($page)->order("id DESC")->select();
		
		$this->assign('lists', $lists);
		$this->showPage($count, $pagesize);
		$this->display();
	}
	
}